﻿#include "lua_obj.h"

static int lua_lv_canvas_set_buffer(lua_State *L)
{
    LUA_USER_PRINT(__func__);
    lv_obj_t *a = *(lv_obj_t **)luaL_checkudata(L, 1, META_CANVAS);

    return 0;
}

static int lua_lv_canvas_set_px_color(lua_State *L)
{
    LUA_USER_PRINT(__func__);
    lv_obj_t *a = *(lv_obj_t **)luaL_checkudata(L, 1, META_CANVAS);

    return 0;
}

static int lua_lv_canvas_set_px(lua_State *L)
{
    LUA_USER_PRINT(__func__);
    lv_obj_t *a = *(lv_obj_t **)luaL_checkudata(L, 1, META_CANVAS);

    return 0;
}

static int lua_lv_canvas_set_px_opa(lua_State *L)
{
    LUA_USER_PRINT(__func__);
    lv_obj_t *a = *(lv_obj_t **)luaL_checkudata(L, 1, META_CANVAS);

    return 0;
}

static int lua_lv_canvas_set_palette(lua_State *L)
{
    LUA_USER_PRINT(__func__);
    lv_obj_t *a = *(lv_obj_t **)luaL_checkudata(L, 1, META_CANVAS);
    uint8_t id = luaL_checkinteger(L, 2);

    return 0;
}

static int lua_lv_canvas_get_px(lua_State *L)
{
    LUA_USER_PRINT(__func__);
    lv_obj_t *a = *(lv_obj_t **)luaL_checkudata(L, 1, META_CANVAS);

    return 0;
}

static int lua_lv_canvas_get_img(lua_State *L)
{
    LUA_USER_PRINT(__func__);
    lv_obj_t *a = *(lv_obj_t **)luaL_checkudata(L, 1, META_CANVAS);

    return 0;
}

static int lua_lv_canvas_copy_buf(lua_State *L)
{
    LUA_USER_PRINT(__func__);
    lv_obj_t *a = *(lv_obj_t **)luaL_checkudata(L, 1, META_CANVAS);

    return 0;
}

static int lua_lv_canvas_transform(lua_State *L)
{
    LUA_USER_PRINT(__func__);
    lv_obj_t *a = *(lv_obj_t **)luaL_checkudata(L, 1, META_CANVAS);
    int16_t angle = luaL_checkinteger(L, 3);
    uint16_t zoom = luaL_checkinteger(L, 4);
   
                         int32_t pivot_x = luaL_checkinteger(L, 7);
    int32_t pivot_y = luaL_checkinteger(L, 8);

    return 0;
}

static int lua_lv_canvas_blur_hor(lua_State *L)
{
    LUA_USER_PRINT(__func__);
    lv_obj_t *a = *(lv_obj_t **)luaL_checkudata(L, 1, META_CANVAS);

    return 0;
}

static int lua_lv_canvas_blur_ver(lua_State *L)
{
    LUA_USER_PRINT(__func__);
    lv_obj_t *a = *(lv_obj_t **)luaL_checkudata(L, 1, META_CANVAS);

    return 0;
}

static int lua_lv_canvas_fill_bg(lua_State *L)
{
    LUA_USER_PRINT(__func__);
    lv_obj_t *a = *(lv_obj_t **)luaL_checkudata(L, 1, META_CANVAS);

    return 0;
}

static int lua_lv_canvas_draw_rect(lua_State *L)
{
    LUA_USER_PRINT(__func__);
    lv_obj_t *a = *(lv_obj_t **)luaL_checkudata(L, 1, META_CANVAS);

    return 0;
}

static int lua_lv_canvas_draw_text(lua_State *L)
{
    LUA_USER_PRINT(__func__);
    lv_obj_t *a = *(lv_obj_t **)luaL_checkudata(L, 1, META_CANVAS);

    return 0;
}

static int lua_lv_canvas_draw_img(lua_State *L)
{
    LUA_USER_PRINT(__func__);
    lv_obj_t *a = *(lv_obj_t **)luaL_checkudata(L, 1, META_CANVAS);

    return 0;
}

static int lua_lv_canvas_draw_line(lua_State *L)
{
    LUA_USER_PRINT(__func__);
    lv_obj_t *a = *(lv_obj_t **)luaL_checkudata(L, 1, META_CANVAS);
    uint32_t point_cnt = luaL_checkinteger(L, 3);

    return 0;
}

static int lua_lv_canvas_draw_polygon(lua_State *L)
{
    LUA_USER_PRINT(__func__);
    lv_obj_t *a = *(lv_obj_t **)luaL_checkudata(L, 1, META_CANVAS);
    uint32_t point_cnt = luaL_checkinteger(L, 3);

    return 0;
}

static int lua_lv_canvas_draw_arc(lua_State *L)
{
    LUA_USER_PRINT(__func__);
    lv_obj_t *a = *(lv_obj_t **)luaL_checkudata(L, 1, META_CANVAS);
    int32_t start_angle = luaL_checkinteger(L, 5);
   
                        int32_t end_angle = luaL_checkinteger(L, 6);

    return 0;
}

static int lua_auto_gc(lua_State *L)
{
    lv_obj_t *lv_obj = *(lv_obj_t **)luaL_checkudata(L, 1, META_CANVAS);
    luaL_argcheck(L, lv_obj != NULL, 1, "invalid user data");
    if (lv_obj)
    {
        lv_obj_del(lv_obj);
    }
    return 0;
}
static const struct luaL_Reg arraylib_m[] = {
    {"set_buffer", lua_lv_canvas_set_buffer},
    {"set_px_color", lua_lv_canvas_set_px_color},
    {"set_px", lua_lv_canvas_set_px},
    {"set_px_opa", lua_lv_canvas_set_px_opa},
    {"set_palette", lua_lv_canvas_set_palette},
    {"get_px", lua_lv_canvas_get_px},
    {"get_img", lua_lv_canvas_get_img},
    {"copy_buf", lua_lv_canvas_copy_buf},
    {"transform", lua_lv_canvas_transform},
    {"blur_hor", lua_lv_canvas_blur_hor},
    {"blur_ver", lua_lv_canvas_blur_ver},
    {"fill_bg", lua_lv_canvas_fill_bg},
    {"draw_rect", lua_lv_canvas_draw_rect},
    {"draw_text", lua_lv_canvas_draw_text},
    {"draw_img", lua_lv_canvas_draw_img},
    {"draw_line", lua_lv_canvas_draw_line},
    {"draw_polygon", lua_lv_canvas_draw_polygon},
    {"draw_arc", lua_lv_canvas_draw_arc},
    LUA_LV_OBJ_RLT,
    {NULL, NULL}};

static int help(lua_State *L)
{
    uint16_t n = sizeof(arraylib_m) / sizeof(struct luaL_Reg);
    for (int i = 0; i < n - 1; i++)
    {
        printf("%s\n", arraylib_m[i].name);
    }
    return 1;
}

static const struct luaL_Reg arraylib_f[] = {
    {"help", help},
    {NULL, NULL}};

LUALIB_API int lua_lv_canvas_funinit(lua_State *L)
{
    luaL_newlib(L, arraylib_f);
    luaL_newmetatable(L, META_CANVAS);  /* create metatable for file handles */
    lua_pushvalue(L, -1);            /* push metatable */
    lua_setfield(L, -2, "__index");  /* metatable.__index = metatable */
    luaL_setfuncs(L, arraylib_m, 0); /* add file methods to new metatable */
    lua_pop(L, 1);                   /* pop new metatable */

    return 1;
}
